package com.example.chatgpt.controller;

import com.example.chatgpt.model.OpenAIResponse;
import com.example.chatgpt.service.ChatgptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.CompletableFuture;

@CrossOrigin(origins = "*", methods = {RequestMethod.POST, RequestMethod.OPTIONS})
@RestController
@RequestMapping("/api/chat")
public class ChatgptController {

    @Autowired
    private ChatgptService chatgptService;

    @PostMapping("/ask")
    public CompletableFuture<OpenAIResponse> askChatGPT(@RequestBody String question) {
        System.out.println("The Controller Accepts Request!");
        return chatgptService.askChatGPTAsync(question);
    }
}
